<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id='app' v-cloak>
    <cpn></cpn>
    <cpn></cpn>
    <cpn></cpn>
  </div>
  <template id="cpn">
    <div>
      <h2>{{title}}</h2>
      <p>我是内容</p>
      <h2>当前计数：{{counter}}</h2>
      <button @click="inc">+</button>
      <button @click="dec">-</button>
    </div>
  </template>
  <script src='../js/vue.js'></script>
  <script>
    // 1.注册全局组件,有生命周期，有methods
    Vue.component('cpn', {
      template: '#cpn',
      data() {
        //每次调用都会生成对应的内存地址
        // 组件数据存放在这里
        return {
          title: '哈哈，我是组件内容',
          counter: 0,
        }
      },
      methods: {
        inc() {
          this.counter++
        },
        dec() {
          this.counter--
        }
      }
    })
    const app = new Vue({
      el: '#app',
      data: {
        message: 'hello Vue'
      }
    })
  </script>
  <style>
    [v-cloak] {
      display: none;
    }
  </style>
</body>

</html>